﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TeamNitro.App_Code;
using System.Collections;
using System.Web.Security;
using System.Runtime.InteropServices;

namespace TeamNitro
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
              //  tbxUsername.Focus();

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            String AdminNumber = tbxUsername.Text;
            String Password = FormsAuthentication.HashPasswordForStoringInConfigFile(tbxPassword.Text, "sha1");

            if (AdminNumber == "teamnitro2011" && Password == FormsAuthentication.HashPasswordForStoringInConfigFile("teamnitro2011", "sha1"))
            {
                DBManager info = new DBManager();
                info.AdminID = "teamnitro2011";
                info.AdminName = "Team Nitro";
                info.Password = Password;
                Session["Admin"] = info;
                FormsAuthentication.RedirectFromLoginPage(tbxUsername.Text, false);

                Response.Redirect("~/Admin/AdminHome.aspx");
            }

            else if (AdminNumber.Count() == 8)
            {
                bool result = DBManager_Rex.StudentLogin(AdminNumber, Password);
                if (result == true)
                {
                    DBManager_Jowie info = DBManager_Jowie.GetStudentInfo(tbxUsername.Text);
                    Session["Student"] = info;
                    FormsAuthentication.RedirectFromLoginPage(tbxUsername.Text, false);
                    Response.Redirect("~/Student/Students_Home.aspx");
                }
                else
                {
                    Label1.Visible = true;
                    //Response.Redirect("Default.aspx");
                    
                }
            }
            else if (AdminNumber.Count() == 7)
            {

            }
            else if (AdminNumber.Count() == 6)
            {
                bool result = DBManager_Rex.AdminLogin(AdminNumber, Password);
                if (result == true)
                {
                    DBManager info = DBManager.GetAdminInfo(tbxUsername.Text);
                    Session["Admin"] = info;
                    FormsAuthentication.RedirectFromLoginPage(tbxUsername.Text, false);
                    Response.Redirect("~/Admin/AdminHome.aspx");
                }
                else
                {
                    Label1.Visible = true;
                    //Response.Redirect("Default.aspx");

                }
            }
            else
            {
                Label1.Visible = true;
            }



        }

    }
}